package com.beta.service.impl;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.beta.entity.Categories;
import com.beta.mapper.CategoriesMapper;
import com.beta.service.ICategoriesService;
import com.beta.service.ServiceException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Categories 表数据服务层接口实现类
 */
@Service
public class CategoriesService extends SuperServiceImpl<CategoriesMapper, Categories> implements ICategoriesService {

    @Override
    public List<Categories> getAllCategories() {
        return (selectList(new EntityWrapper<Categories>().orderBy("position", false)));
    }

    @Override
    public List<Categories> getCategories(Integer userId){
        if(Objects.isNull(userId)){
            throw new ServiceException("E00113");
        }
        return (baseMapper.getSignedCategories(userId));
    }

}